# Every PacketInterpreter found in the sources are added to the compilation (lidar, HDLPosition, ...)
# This allow to compile private interpreter (that not appear in the public repository)
# without changing the cmakelist in the private repository
file(GLOB_RECURSE velodyneInterpreter_xml ${CMAKE_CURRENT_SOURCE_DIR}/*PacketInterpreter*.xml)
file(GLOB_RECURSE velodyneInterpreter_cxx ${CMAKE_CURRENT_SOURCE_DIR}/*PacketInterpreter*.cxx)

if(velodyneInterpreter_cxx MATCHES "SpecialVelarray")
  add_definitions(-DVELOVIEW_HAS_VELARRAY=TRUE)
endif()

set(server_manager_xml
  ${velodyneInterpreter_xml}
  )

set(server_manager_sources
  ${velodyneInterpreter_cxx}
  ${CMAKE_CURRENT_SOURCE_DIR}/PlaneFitter/vtkPlaneFitter.cxx
  )

set(server_sources
  ${CMAKE_CURRENT_SOURCE_DIR}/VelodynePacketInterpreter/vtkRollingDataAccumulator.cxx
  ${CMAKE_CURRENT_SOURCE_DIR}/VelodynePacketInterpreter/vtkVelodyneAdvancedPacketFraming.cxx
  )

ADD_PARAVIEW_PLUGIN(VelodynePlugin "1.0"
  REQUIRED_ON_SERVER
  SERVER_MANAGER_XML ${server_manager_xml}
  SERVER_MANAGER_SOURCES ${server_manager_sources}
  SERVER_SOURCES ${server_sources}
  REQUIRED_ON_SERVER)

target_link_libraries(VelodynePlugin PUBLIC LidarPlugin)
target_include_directories(VelodynePlugin
  PUBLIC
  PlaneFitter/
  VelodynePacketInterpreter/
  VelodyneHDLPositionPacketInterpreter/
  )


set(towrap
    "${CMAKE_CURRENT_SOURCE_DIR}/PlaneFitter/vtkPlaneFitter.cxx"
    )
WRAP_PLUGIN_FOR_PYTHON(VelodynePlugin "${towrap}" "NOTTHERE")

set(libraries_to_install
  VelodynePlugin
  VelodynePluginPython
  VelodynePluginPythonD
  )


# install libraries
if (APPLE)
  install(TARGETS ${libraries_to_install}
          RUNTIME DESTINATION ${VV_INSTALL_RUNTIME_DIR}/${SOFTWARE_NAME}.app/Contents/Libraries
          LIBRARY DESTINATION ${VV_INSTALL_RUNTIME_DIR}/${SOFTWARE_NAME}.app/Contents/Libraries
          COMPONENT Runtime)
else()
  install(TARGETS ${libraries_to_install}
          RUNTIME DESTINATION ${VV_INSTALL_RUNTIME_DIR}
          LIBRARY DESTINATION ${VV_INSTALL_LIBRARY_DIR}
          COMPONENT Runtime)
endif()

# Install data files
set (calib_files
  VLP-16.xml
  HDL-32.xml
  VLP-32c.xml
  "Puck Hi-Res.xml"
  "Puck LITE.xml"
  "Alpha Prime.xml")

# copy the calibration to the build folder
foreach(file ${calib_files})
  configure_file("CalibrationsFiles/${file}" "${PROJECT_BINARY_DIR}/share/${file}" COPYONLY)
endforeach()

# install step
set(installfile_dest share)
if(APPLE)
  set(installfile_dest "${VV_INSTALL_RUNTIME_DIR}/${SOFTWARE_NAME}.app/Contents/Resources")
endif()
foreach(file ${calib_files})
  install(FILES "${PROJECT_BINARY_DIR}/share/${file}" DESTINATION ${installfile_dest})
endforeach()

#-----------------------------------------------------------------------------
# Option to build some tests
#-----------------------------------------------------------------------------
option(BUILD_TESTING "Build some unitary test" OFF)
if(BUILD_TESTING)
  add_subdirectory(Testing)
endif()
